package com.example.zhongyingkaoshi.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@RestController
public class ExamDataController {

    @GetMapping("/api/tongji")
    public Map<String, Object> getExamData() {
        Map<String, Object> data = new HashMap<>();
        // 模拟考试数据
        data.put("total", 100);
        data.put("attended", 80);
        data.put("unattended", 20);
        data.put("chartData", Arrays.asList(8, 6, 7, 5, 8, 4, 3));
        return data;
    }

    @PostMapping("/scoreQuery")
    public Map<String, Object> queryScore(@RequestBody Map<String, String> request) {
        String studentName = request.get("studentName");
        String region = request.get("region");
        Map<String, Object> result = new HashMap<>();
        
        // 新增模拟字段
        result.put("employeeId", "EMP" + (100000 + (int)(Math.random() * 900000)));
        result.put("email", studentName.toLowerCase() + "@example.com");
        result.put("subjects", Arrays.asList("语文", "数学", "英语", "综合"));
        
        // 分页模拟数据
        Map<String, Object> pageInfo = new HashMap<>();
        pageInfo.put("pageNumber", 1);
        pageInfo.put("pageSize", 10);
        pageInfo.put("total", 100);
        result.put("page", pageInfo);
        
        // 保留原始字段
        result.put("studentName", studentName);
        result.put("region", region);
        result.put("score", (int) (Math.random() * 100));
        
        return result;
    }
}

